﻿using CatUtils.Utils.Currency.IoUtils;

using CatUtils.Utils.SpecialUtils.Html;
using CatUtils.Utils.SpecialUtils.View;
using RabbitDownload.Helper.Currency;

using RabbitDownload.Helper.ViewHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RabbitDownload.WebSite
{
    internal class SiteCurrencyHelper
    {
        /// <summary>
        /// 存储进度变更
        /// </summary>
        /// <param name="TagList"></param>
        public void SaveDownloadProcess(string FilePath, List<string> TagList)
        {
            string TempFile = FileNameHelper.CreateFileNameWithExtension(FilePath, ".tmp");
            FileHelper.WriteList(TempFile, TagList);
            if (TagList.Count == 0)
                FileHelper.FileDelete(TempFile);
        }

        /// <summary>
        /// 获取下是否存在上次下载进度
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="Xpath"></param>
        /// <returns></returns>
        public List<string> GetDownoadProcess(string FilePath, string Xpath)
        {
            List<string> TagList = HtmlHelper.GetHtmlValueList(FileHelper.ReadAllText(FilePath), Xpath);
            string TempFile = FileNameHelper.CreateFileNameWithExtension(FilePath, ".tmp");
            if (FileHelper.FileExits(TempFile))
            {
                if (MessageHelper.DialogResultAlert("是否从上次进度继续下载？"))
                    TagList = HtmlHelper.GetHtmlValueList(FileHelper.ReadAllText(TempFile), "//item");
            }
            return TagList;
        }
    }
}